//
//  UserInterfaceMagager.swift
//  ServiceCode
//
//  Created by 曹连华 on 2020/12/21.
//

import UIKit
import CoreCode
@available(iOS 13.0, *)
@objc public class UserInterfaceMagager: NSObject {
    @objc public static let manager = UserInterfaceMagager()
    @objc public lazy var currentStyle: UIUserInterfaceStyle = {
        
        if UserDefaults.standard.object(forKey: "UserInterfaceStyle") == nil {
            return .unspecified
        } else {
            return UIUserInterfaceStyle(rawValue: UserDefaults.standard.object(forKey: "UserInterfaceStyle") as! Int) ?? .unspecified
        }
    }()
    
    private override init() {}
    
    @objc public class func updateUserInterfaceStyle(_ style : UIUserInterfaceStyle) {
        manager.currentStyle = style
        UserDefaults.standard.setValue(NSNumber(value: manager.currentStyle.rawValue), forKey: "UserInterfaceStyle")
        UIApplication.shared.windows.first?.overrideUserInterfaceStyle = manager.currentStyle
        
    }
}
 
